// EDataTable

// Base
@mixin e-datatable-base() {
	$page-size: 2.25rem;
	$table-space: e-get($card, space, desktop);
	$table-space-mobile: e-get($card, space, mobile);

	.e-datatable {
		display: none;
	}

	.e-datatable.e-datatable--default {
		display: block;
		margin-bottom: $table-space;

		// Base
		> .e-datatable__table {
			border-collapse: collapse;
			overflow: hidden;
			display: none;
			width: 100%;

			> .e-datatable__head,
			> .e-datatable__body,
			> .e-datatable__foot {
				visibility: hidden;
				display: block;

				.e-datatable__row {
					width: 100%;

					> .e-datatable__cell {
						// Row cell base
						vertical-align: middle;
						padding: 3px 10px;
						font-size: 1rem;
						height: 40px;
						min-height: 40px;

						&:first-child {
							padding-left: $table-space;
						}

						&:last-child {
							padding-right: $table-space;
						}

						.table-actions{
							border-color: transparent;
							background: transparent;
							color: #93a2dd;
						}

						i {
							//font-size: 1.4rem;
						}

						&.e-datatable__cell--left {
							text-align: left;
							> span {
								text-align: left;
							}
						}

						&.e-datatable__cell--right {
							text-align: right;
							> span {
								text-align: right;
								> i {
									right: 0;
								}
							}
						}

						&.e-datatable__cell--center {
							text-align: center;
							> span {
								text-align: center;
							}
						}

						&.e-datatable__cell--sort {
							cursor: pointer;

							i {
								font-size: .6rem;
							}
						}

						&.e-datatable__cell--resizing {
							cursor: col-resize;
						}

						> span {
							display: block;
							overflow: hidden;
							text-overflow: ellipsis;
                            white-space:nowrap
						}

						// Row checkbox
						&.e-datatable__cell--check {
							text-align: center;

							> span {
								overflow: visible;

								> .e-checkbox {
									top: 2px;
									padding: 0;
									margin: 0 0 0 0;
								}
							}
						}
						.e-switch {
							label, span {
								margin: 0;
							}

							&.e-switch--sm {
								margin-top: 5px;
							}
						}

						// Row details
						&.e-datatable__toggle-detail {
							> span {
								width: 12px;
							}
							> .e-datatable__toggle-detail {
								display: inline-block;
								text-align: right;

								> i {
									font-size: 1.4rem;
									width: 12px;
								}
							}
						}

						// Cell dropdown menu
						.dropdown {
							display: inline-block;

							.dropdown-menu {
								margin-top: .5rem;
							}

							&.dropup {
								.dropdown-menu {
									margin-top: auto;
									margin-bottom: .5rem;
								}
							}

							.dropdown-menu.dropdown-menu-right {
								margin-right: -.8rem;
								/*rtl:ignore*/
								margin-left: 65px;
							}

							.dropdown-menu.dropdown-menu-left {
								margin-left: -10rem;
							}
						}
					}
				}

				> .e-datatable__lock {
					border: 0;
				}
			}

			> .e-datatable__head,
			> .e-datatable__foot {
				.e-datatable__row {
					> .e-datatable__cell {
						> span {
							font-weight: 500;
							vertical-align: middle;
						}
					}
				}
			}

			> .e-datatable__head {
				.e-datatable__row {
					> .e-datatable__cell {
						padding: 16px 10px;

						> span {
							> i {
								display: inline-block;
								position: relative;
								right: -10px;
								line-height: 0;
								vertical-align: middle;
								font-size: 1.1rem;
							}
						}
					}
				}
			}

			> .e-datatable__body {
				&.ps {
					padding-bottom: 0;
				}

				.e-datatable__row {
					> .e-datatable__cell {
						font-weight: regular;

						&.e-datatable__cell--check {
							> span {
								> .e-checkbox {
									top: 1px;
								}
							}
						}
					}
				}

				.e-datatable__row-detail {
					display: block;
					.e-datatable__detail {
						display: block;
						padding: 0 ($table-space + 35px);

						.e-datatable__row {
							display: table-row;

							> .e-datatable__cell {
								padding: 8px 12px;
								text-align: left;
								vertical-align: top;

								> span {
									width: auto !important;
								}

								&:first-child {
									font-weight: 500;
								}

								&:last-child {
									font-weight: regular;
									padding-left: 20px;
								}
							}
						}
					}
				}
			}
		}

		// Error message
		&.e-datatable--error {
			.e-datatable__body {
				padding: 30px;
				text-align: center;
			}
		}

		// Lock state
		&.e-datatable--lock {
			> .e-datatable__table {
				> .e-datatable__head,
				> .e-datatable__body,
				> .e-datatable__foot {
					> .e-datatable__lock {
						display: inline-block;
						position: relative;
						vertical-align: top;
						overflow: hidden;
					}
				}
			}
		}

		// Loaded state
		&.e-datatable--loaded {
			display: block;

			> .e-datatable__table {
				display: block;

				> .e-datatable__head,
				> .e-datatable__body,
				> .e-datatable__foot {
					visibility: visible;
					display: block;
					position: relative;

					.e-datatable__row {
						display: table;
						table-layout: initial;

						> .e-datatable__cell {
							//display: table-cell;
						}
					}
				}
			}
		}

		// Scrollable state
		&.e-datatable--scroll {
			> .e-datatable__table {
				display: block;

				> .e-datatable__head,
				> .e-datatable__body,
				> .e-datatable__foot {
				}

				> .e-datatable__head,
				> .e-datatable__foot {
					overflow: hidden;

					.e-datatable__row {
						position: relative;
					}
				}

				> .e-datatable__body {
					overflow: hidden;
				}
			}
		}

		> .e-datatable__pager {
			margin: 0;
			padding: $table-space;
			padding-bottom: 0;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			&.e-datatable__pager--top {
				margin-bottom: 20px;
			}

			> .e-datatable__pager-nav {
				margin: 0;
				padding: 0;
				display: flex;

				> li {
					padding: 0;
					margin-right: 5px;
					display: inline-block;

					&:last-child {
						margin-right: 0;
					}

					> .e-datatable__pager-link {
						cursor: pointer;
						display: flex;
						justify-content: center;
						align-items: center;
						height: $page-size;
						min-width: $page-size;
						padding: .5rem;
						border-radius: 3px;

						@include e-not-rounded {
							border-radius: 0;
						}

						position: relative;
						font-size: 1rem;
						line-height: 1rem;
						font-weight: 500;

						> i {
							font-size: .6rem;
							text-align: center;
							display: inline-block;
						}

						&.e-datatable__pager-link--more-prev,
						&.e-datatable__pager-link--more-next {
							font-weight: 600;
						}
					}

					> .e-pager-input {
						height: $page-size;
						width: 3.5rem;
						text-align: center;

						@include e-rounded {
							border-radius: 3px !important;
						}
					}
				}
			}

			> .e-datatable__pager-info {
				display: flex;
				align-items: center;

				.e-datatable__pager-size {
					margin-right: 10px;

					.btn.dropdown-toggle {
						//border-radius: 3px !important;
						height: $page-size;
						padding: .45rem 1rem;

						@include e-not-rounded {
							border-radius: 0 !important;
						}
					}

					.dropdown-menu.inner > li.selected > a span.check-mark {
						margin-top: -.6rem;
					}
				}
			}
		}

		// Subtable
		&.e-datatable--subtable {
			> .e-datatable__table {
				margin-bottom: 0;

				> .e-datatable__head,
				> .e-datatable__body,
				> .e-datatable__foot {
					.e-datatable__row {
						//width: 100%;
					}

					.e-datatable__toggle-subtable {
						display: flex;
						justify-content: center;
						align-items: center;

						> i {
							line-height: 0;
							font-size: 1.4rem;
						}

						&:hover {
							text-decoration: none;
						}
					}

					.e-datatable__row-subtable {
						display: table;
						width: 100%;

						> .e-datatable__subtable {
							padding: 20px;

							> .e-datatable {
								> .e-datatable__pager {
									padding-top: 10px;
									padding-bottom: 10px;
								}
							}
						}
					}
				}
			}
		}
	}

	@include e-mobile {
		.e-datatable.e-datatable--default {
			margin-bottom: $table-space-mobile;

			> .e-datatable__table {
				> .e-datatable__head,
				> .e-datatable__body,
				> .e-datatable__foot {
					.e-datatable__row {
						> .e-datatable__cell {
							&:first-child {
								padding-left: $table-space-mobile;
							}

							&:last-child {
								padding-right: $table-space-mobile;
							}
						}
					}
				}
			}

			> .e-datatable__pager {
				margin: 0;
				padding: $table-space-mobile $table-space-mobile $table-space-mobile/2 $table-space-mobile;

				.e-datatable__pager-nav,
				.e-datatable__pager-info {
					margin-top: 10px;
				}
			}
		}
	}
}

// Skin
@mixin e-datatable-skin() {
	.e-datatable {
		// Base color
		$base_color: #f9fbfe;

		// Table
		$base_bg: #fff;

		// Head
		$head_cell_bg: transparent;
		$head_cell_color: e-base-color(label, 3);
		$head_cell_sorted_color: e-state-color(brand);
		$head_cell_icon_color: e-state-color(brand);

		// Checkbox
		$checkbox_bg: e-base-color(shape, 1);
		$checkbox_checked_bg: e-base-color(shape, 2);

		// Row colors
		$row-border-color: e-base-color(shape, 1);
		$row-even: transparent;
		$row-hover: transparent;
		$row-active: e-base-color(grey, 1);

		// Body cell
		$body_cell_font_color: e-base-color(label, 3);

		// Lock table shadow
		$lock-shadow: 0 0 17px 5px rgba(113, 106, 202, .14);

		// Subtable
		$subtable_toggle_icon: e-state-color(brand);
		$subtable_expanded: $row-active;
		$subtable_pager_pagel: $base-color;
		$subtable_shadow: 0 0 15px 1px rgba(113, 106, 202, .1);

		$detail_icon_color: e-state-color(brand); //e-base-color(shape, 2);
	    $detail_icon_color_hover: e-state-color(brand);

		// Pagination colors
		$page-default: e-base-color(shape, 1);
		$page-default-font: e-base-color(shape, 3);
		$page-hover: e-state-color(brand);
		$page-hover-font: e-state-color(brand, inverse);
		$page-active: e-state-color(brand);
		$page-active-font: e-state-color(brand, inverse);

		$page-info: e-base-color(shape, 1);
		$page-info-font: e-base-color(shape, 3);
		$page-info-hover: e-state-color(brand);
		$page-info-hover-font: e-state-color(brand, inverse);

		// Base Table
		> .e-datatable__table {
			background-color: $base_bg;
			//border-bottom: 1px solid $row-border-color;

			// General
			> .e-datatable__head,
			> .e-datatable__body,
			> .e-datatable__foot {
				> .e-datatable__lock {
					&.e-datatable__lock--left {
						z-index: 1;
						box-shadow: $lock-shadow;
					}

					&.e-datatable__lock--right {
						box-shadow: $lock-shadow;
					}

					&.e-datatable__lock--scroll {
						position: relative;
					}
				}

				.e-datatable__row {
					border-bottom: 1px solid $row-border-color;

					> .e-datatable__cell {
						.e-checkbox.e-checkbox--solid > span {
							background: $checkbox_bg;
						}

						.e-checkbox.e-checkbox--solid > input:checked ~ span {
							background: $checkbox_checked_bg;
						}
					}
				}
			}

			// Body
			> .e-datatable__body {
				.e-datatable__toggle-detail {
					vertical-align: middle;
					i {
						transition: color .3s ease;
						color: $detail_icon_color;

						&:before {
							line-height: 0;
							vertical-align: middle;
						}
					}

					&:hover,
					&.e-datatable__toggle-detail--active {
						i {
							transition: color .3s ease;
							color: $detail_icon_color_hover;
						}
					}
				}

				.e-datatable__row-detail {
					.e-datatable__detail {
						table {
							border-left: 1px solid $row-border-color;
							border-right: 1px solid $row-border-color;
						}
					}
				}
			}

			// Head & Foot
			> .e-datatable__head,
			> .e-datatable__foot {
				.e-datatable__row {
					> .e-datatable__cell {
						background: $head_cell_bg;

						> span {
							color: $head_cell_color;
						}
					}
				}
			}

			// Head
			> .e-datatable__head {
				.e-datatable__row {
					> .e-datatable__cell {
						> span {
							> i {
								color: $head_cell_icon_color;
							}
						}
					}
				}
			}

			// Error message
			&.e-datatable--error {
				.e-datatable__body {
					.e-datatable__error {

					}
				}
			}
		}

		// Pagination
		> .e-datatable__pager {
			> .e-datatable__pager-nav {
				> li {
					> .e-datatable__pager-link {
						color: $page-default-font;

						@include e-transition();

						&.e-datatable__pager-link--first,
						&.e-datatable__pager-link--prev,
						&.e-datatable__pager-link--next,
						&.e-datatable__pager-link--last {
							background: $page-default;

							&:hover {
								background: $page-hover;
								color: $page-hover-font;
							}
						}

						&:hover {
							@include e-transition();
							background: $page-hover;
							color: $page-hover-font;
						}

						&.e-datatable__pager-link--active {
							background: $page-active;
							color: $page-active-font;
						}

						&.e-datatable__pager-link--disabled,
						&.e-datatable__pager-link--disabled:hover {
							color: $page-default-font;
							background: $page-default;
							opacity: .3;
						}
					}

					> .e-pager-input {
						@include e-transition();
						background: $page-default;
						border-color: $page-default;

						&:focus {
							@include e-transition();
							background: $page-hover;
							border-color: $page-hover;
						}
					}
				}
			}

			> .e-datatable__pager-info {
				.e-datatable__pager-size {
					.btn.dropdown-toggle {
						font-size: 1rem;
						font-weight: 500;
						border: 0 !important;
						color: $page-info-font;
						background: $page-info;

						i {
							color: $page-info-hover-font;
						}
					}

					.btn.dropdown-toggle:focus,
					.btn.dropdown-toggle:hover,
					&.show > .btn.dropdown-toggle {
						border: 0 !important;
						color: $page-info-hover-font !important;
						background: $page-info-hover;

						i {
							color: $page-info-hover-font !important;
						}
					}

					.dropdown-menu {
						z-index: 100;

						.modal & {
							z-index: $e-modal-z-index + 1;
						}
					}
				}
			}
		}

		// Subtable
		&.e-datatable--subtable {
			> .e-datatable__table {
				> .e-datatable__body {
					.e-datatable__toggle-subtable {
						> i {
							color: $subtable_toggle_icon;
						}
					}

					.e-datatable__row-subtable {
						border-top: 0;

						.e-datatable__pager {
							//background: $subtable_pager_pagel;
						}
					}
				}
			}
		}

		// Default Skin
		&.e-datatable--default {
			// Base Table
			> .e-datatable__table {
				> .e-datatable__body {
					.e-datatable__row {
						> .e-datatable__cell {
							transition: background .3s ease;

							> span {
								color: $body_cell_font_color;
							}

							&.e-datatable__cell--hover {
								transition: background .3s ease;
								background: $row-hover;
							}
						}

						&.e-datatable__row--even {
							> .e-datatable__cell {
								background: $row-even;
							}
						}

						&.e-datatable__row--active {
							> .e-datatable__cell {
								background: $row-active;
							}
						}

						&.e-datatable__row--hover:not(.e-datatable__row--active) {
							transition: background .3s ease;

							> .e-datatable__cell {
								transition: background .3s ease;
								background: $row-hover;
							}
						}
					}
				}

				> .e-datatable__head,
				> .e-datatable__foot {
					.e-datatable__row {
						> .e-datatable__cell {
							&.e-datatable__cell--sorted {
								> span {
									color: $head_cell_sorted_color;
								}
							}
						}
					}
				}

			}

			// Subtable
			&.e-datatable--subtable {
				> .e-datatable__table {
					> .e-datatable__body {
						.e-datatable__row {
							&.e-datatable__row--subtable-expanded {
								> .e-datatable__cell {
									background: $subtable_expanded !important;
								}
							}
						}

						.e-datatable__row-subtable {
							background: $row-even;

							> .e-datatable__subtable {
								> .e-datatable {
									box-shadow: $subtable_shadow;
								}
							}

							&.e-datatable__row-loading {
								> .e-datatable__subtable {
									> .e-datatable {
										> .e-datatable__table {
											background: $row-even;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

// Build
// Base
@include e-datatable-base();

// Skin
@include e-datatable-skin();
